<?php

namespace App\Http\Controllers;

use App\Services\MessageService;

class MessageController extends Controller
{
    public $messageService;

    public function __construct(MessageService $messageService)
    {
        parent::__construct();
        $this->messageService = $messageService;
    }

    /**
     * 获取消息列表
     */
    public function index()
    {
         $data = $this->messageService->getMessages();

         return $this->success($data);
    }

    /**
     * 全部标记为已读
     */
    public function setHadRead()
    {
        if (!$this->messageService->setHadRead()) {
            return $this->error('操作失败！');
        }

        return $this->success('', '标记成功！');
    }

    /**
     * 未读消息数量
     */
    public function noReadCount()
    {
        $count = $this->messageService->getNoReadCount();
        $data  = [
            'no_read_count' => $count
        ];
        return $this->success($data);
    }

}
